package com.ruoyi.project.modules.parameter.service.impl;

import java.util.*;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.modules.frontInterfaceFieldSource.mapper.FrontInterfaceFieldSourceMapper;
import com.ruoyi.project.modules.interfaceObject.mapper.InterfaceObjectMapper;
import com.ruoyi.project.modules.interfaceObject.service.IInterfaceObjectService;
import com.ruoyi.project.modules.interfaceinfo.domain.InterfaceInfo;
import com.ruoyi.project.modules.interfaceinfo.domain.VirtualUsage;
import com.ruoyi.project.modules.interfaceinfo.request.BffParamReq;
import com.ruoyi.project.modules.interfaceinfo.request.ListInterfaceFieldParamReq;
import com.ruoyi.project.modules.interfaceinfo.request.VirtualUsageParamReq;
import com.ruoyi.project.modules.interfaceinfo.service.IInterfaceInfoService;
import com.ruoyi.project.modules.interfaceinfo.service.IVirtualUsageService;
import com.ruoyi.project.modules.interfaceinfo.vo.InterfaceParam;
import com.ruoyi.project.modules.parameter.domain.ParamTree;
import com.ruoyi.project.modules.parameter.domain.Params;
import com.ruoyi.project.modules.parameter.domain.ParamsFieldRelation;
import com.ruoyi.project.modules.parameter.mapper.ParamsFieldRelationMapper;
import com.ruoyi.project.modules.parameter.mapper.ParamsMapper;
import com.ruoyi.project.modules.processBranch.domain.ProcessBranch;
import com.ruoyi.project.modules.processBranch.service.IProcessBranchService;
import com.ruoyi.project.modules.processBranchCondition.domain.ProcessBranchCondition;
import com.ruoyi.project.modules.processBranchCondition.service.IProcessBranchConditionService;
import com.ruoyi.project.modules.processBranchConditionDetail.domain.ProcessBranchConditionDetail;
import com.ruoyi.project.modules.processBranchConditionDetail.service.IProcessBranchConditionDetailService;
import com.ruoyi.project.modules.table.domain.FieldInfo;
import com.ruoyi.project.modules.table.domain.FieldStatus;
import com.ruoyi.project.modules.table.domain.TableInfo;
import com.ruoyi.project.modules.virtualUsageFieldMerge.mapper.VirtualUsageFieldMergeMapper;
import com.ruoyi.project.modules.virtualUsageGroup.domain.VirtualUsageGroup;
import com.ruoyi.project.modules.virtualUsageGroup.service.IVirtualUsageGroupService;
import com.ruoyi.project.modules.virtualUsageParamSource.domain.VirtualUsageParamSource;
import com.ruoyi.project.modules.virtualUsageParamSource.mapper.VirtualUsageParamSourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.modules.parameter.mapper.InterfaceParamsFieldRelationMapper;
import com.ruoyi.project.modules.parameter.domain.InterfaceParamsFieldRelation;
import com.ruoyi.project.modules.parameter.service.IInterfaceParamsFieldRelationService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 接口下数据集及字段Service业务层处理
 *
 * @author smallrain
 * @date 2021-10-30
 */
@Service
public class InterfaceParamsFieldRelationServiceImpl implements IInterfaceParamsFieldRelationService {
    @Resource
    private InterfaceParamsFieldRelationMapper interfaceParamsFieldRelationMapper;
    @Resource
    private ParamsMapper paramsMapper;

    /**
     * 查询接口下数据集及字段
     *
     * @param id 接口下数据集及字段主键
     * @return 接口下数据集及字段
     */
    @Override
    public InterfaceParamsFieldRelation selectInterfaceParamsFieldRelationById(Long id) {
        return interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationById(id);
    }

    /**
     * 查询接口下数据集及字段列表
     *
     * @param interfaceParamsFieldRelation 接口下数据集及字段
     * @return 接口下数据集及字段
     */
    @Override
    public List<InterfaceParamsFieldRelation> selectInterfaceParamsFieldRelationList(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        return interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation);
    }

    @Autowired
    private IInterfaceObjectService interfaceObjectService;

    /**
     * 新增接口下数据集及字段
     *
     * @param interfaceParamsFieldRelation 接口下数据集及字段
     * @return 结果
     */
    @Override
    public int insertInterfaceParamsFieldRelation(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        interfaceParamsFieldRelation.setCreateTime(DateUtils.getNowDate());
        if ("2".equals(interfaceParamsFieldRelation.getObjectType()) && interfaceParamsFieldRelation.getObjectId() == null) {
            // 保存
            Params params = new Params();
            params.setEnName(interfaceParamsFieldRelation.getParamsEnName());
            params.setZhName(interfaceParamsFieldRelation.getParamsName());
            params.setIsInParam(interfaceParamsFieldRelation.getIsInParam());
            this.paramsMapper.insertParams(params);
            interfaceParamsFieldRelation.setObjectId(params.getId());
        } else if ("1".equals(interfaceParamsFieldRelation.getObjectType()) && interfaceParamsFieldRelation.getTableId() != null) {
            // 只保存dubbo接口和表关系
            interfaceObjectService.insertInterfaceObject(interfaceParamsFieldRelation.getTableId(), interfaceParamsFieldRelation.getInterfaceId(), "1");
        }
        // TODO 关联接口id未获取
        return interfaceParamsFieldRelationMapper.insertInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
    }

    /**
     * 修改接口下数据集及字段
     *
     * @param interfaceParamsFieldRelation 接口下数据集及字段
     * @return 结果
     */
    @Override
    public int updateInterfaceParamsFieldRelation(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        interfaceParamsFieldRelation.setUpdateTime(DateUtils.getNowDate());
        return interfaceParamsFieldRelationMapper.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
    }

    /**
     * 批量删除接口下数据集及字段
     *
     * @param ids 需要删除的接口下数据集及字段主键
     * @return 结果
     */
    @Override
    public int deleteInterfaceParamsFieldRelationByIds(String ids) {
        return interfaceParamsFieldRelationMapper.deleteInterfaceParamsFieldRelationByIds(Convert.toStrArray(ids));
    }

    @Resource
    private InterfaceObjectMapper interfaceObjectMapper;
    @Resource
    private ParamsFieldRelationMapper paramsFieldRelationMapper;
    /**
     * 删除接口下数据集及字段信息
     *
     * @param id 接口下数据集及字段主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteInterfaceParamsFieldRelationById(Long id) {
        // 查询当前参数是否是dubbo
        InterfaceParamsFieldRelation interfaceParamsFieldRelation1 = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationById(id);
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelation = interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationByDataRelationId(Arrays.asList(id), null);
        if (interfaceParamsFieldRelation != null && interfaceParamsFieldRelation.size() > 0) {
            for (InterfaceParamsFieldRelation paramsFieldRelation : interfaceParamsFieldRelation) {
                ids.add(paramsFieldRelation.getId());
            }
        }
        // 删除关联数据
        interfaceParamsFieldRelationMapper.deleteInterfaceParamsFieldRelationByDataRelationId(ids);
        int i = interfaceParamsFieldRelationMapper.deleteInterfaceParamsFieldRelationById(id);
        if ("1".equals(interfaceParamsFieldRelation1.getType())) {
            // 查询接口关联表信息
            List<InterfaceParamsFieldRelation> interfaceParamsFieldRelations = this.interfaceParamsFieldRelationMapper.selectTableIdAndInterfaceIdById(interfaceParamsFieldRelation1.getInterfaceId());
            // 删除多余的接口和表关系
            if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelations)) {
                List<Long> tableIds = new ArrayList<>();
                interfaceParamsFieldRelations.forEach(interfaceParamsField -> tableIds.add(interfaceParamsField.getTableId()));
                this.interfaceObjectMapper.remove(interfaceParamsFieldRelations.get(0).getInterfaceId(), "1", tableIds);
            } else {
                this.interfaceObjectMapper.remove(interfaceParamsFieldRelation1.getInterfaceId(), "1", null);
            }
        }
        if (interfaceParamsFieldRelation1.getObjectType().equals("2")) {
            // 删除数据集和数据集下字段列表
            //this.paramsMapper.deleteParamsById(interfaceParamsFieldRelation1.getObjectId());
            this.paramsFieldRelationMapper.removeByInterfaceDataListId(Arrays.asList(interfaceParamsFieldRelation1.getId()));
        }
        return i;
    }

    @Override
    public List<ParamTree> listFieldParam(String interfaceType, Long interfaceId, String paramType) {
        return interfaceParamsFieldRelationMapper.listFieldParam(interfaceType, interfaceId, paramType);
    }

    @Override
    public List<ParamTree> listParams(String interfaceType, Long interfaceId, String paramType) {
        return interfaceParamsFieldRelationMapper.listParams(interfaceType, interfaceId, paramType);
    }

    @Override
    public List<FieldInfo> selectFieldList(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        return interfaceParamsFieldRelationMapper.selectFieldList(interfaceParamsFieldRelation);
    }

    @Override
    public List<FieldInfo> selectParamsList(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        return interfaceParamsFieldRelationMapper.selectParamsList(interfaceParamsFieldRelation);
    }

    @Override
    public List<FieldInfo> selectParamsFieldList(Long id) {
        return interfaceParamsFieldRelationMapper.selectParamsFieldList(id);
    }

    @Override
    public List<FieldInfo> selectDubboFieldList(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        return interfaceParamsFieldRelationMapper.selectDubboFieldList(interfaceParamsFieldRelation);
    }

    @Override
    public List<FieldInfo> selectDubboParamsList(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        return interfaceParamsFieldRelationMapper.selectDubboParamsList(interfaceParamsFieldRelation);
    }

    @Override
    public List<FieldStatus> selectFieldStatusList(Long id) {
        return interfaceParamsFieldRelationMapper.selectFieldStatusList(id);
    }

    @Override
    public List<FieldStatus> selectFieldStatusListByParamsFieldId(Long id) {
        return interfaceParamsFieldRelationMapper.selectFieldStatusListByParamsFieldId(id);
    }

    @Override
    public List<InterfaceParamsFieldRelation> selectInterfaceParamsFieldRelationByVUids(List<Long> vuIds) {
        return interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationByVUids(vuIds);
    }

    @Override
    public List<TableInfo> tableList(Long interfaceId, String type, Long isInParam) {
        return interfaceParamsFieldRelationMapper.tableList(interfaceId, type, isInParam);
    }

    @Resource
    private VirtualUsageParamSourceMapper virtualUsageParamSourceMapper;

    @Override
    public int saveVirtualUsageParam(VirtualUsageParamReq virtualUsageParamReq) {
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
        interfaceParamsFieldRelation.setIds(virtualUsageParamReq.getId());
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation);
        for (InterfaceParamsFieldRelation paramsFieldRelation : interfaceParamsFieldRelationList) {
            paramsFieldRelation.setDataRelationId(paramsFieldRelation.getId());
            paramsFieldRelation.setId(null);
            paramsFieldRelation.setType(virtualUsageParamReq.getType());
            paramsFieldRelation.setInterfaceId(virtualUsageParamReq.getInterfaceId());
            paramsFieldRelation.setDataRelationType("1");
            paramsFieldRelation.setIsInParam(virtualUsageParamReq.getIsInParam());
            paramsFieldRelation.setObjectType(virtualUsageParamReq.getObjectType());
            paramsFieldRelation.setIsRequiredParent(paramsFieldRelation.getIsRequired());
            if (StringUtils.isNotEmpty(paramsFieldRelation.getDesignContent())) {
                paramsFieldRelation.setIsUpdate("N");
            }
        }
        this.interfaceParamsFieldRelationMapper.batchSave(interfaceParamsFieldRelationList);
        return 1;
    }

    @Override
    public List<InterfaceParam> listInterfaceALlField(ListInterfaceFieldParamReq listInterfaceFieldParamReq) {
        List<InterfaceParam> interfaceParams = new ArrayList<>();
        List<InterfaceParam> interfaceParams1 = this.interfaceParamsFieldRelationMapper.listInterfaceALlField(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(interfaceParams1)) {
            interfaceParams.addAll(interfaceParams1);
        }
        List<InterfaceParam> interfaceParams2 = this.interfaceParamsFieldRelationMapper.listInterfaceALlParamField(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(interfaceParams2)) {
            interfaceParams.addAll(interfaceParams2);
        }

        if (CollectionUtil.isNotEmpty(interfaceParams)) {
            Iterator<InterfaceParam> iterator = interfaceParams.iterator();
            while (iterator.hasNext()) {
                InterfaceParam next = iterator.next();
                if (listInterfaceFieldParamReq.getIsInParam().equals("1") &&
                        StringUtils.isNotEmpty(next.getDesignContent())) {
                    iterator.remove();
                }
            }
        }
        return interfaceParams;
    }

    @Override
    public void saveBffParam(BffParamReq bffParamReq, List<Long> interfaceParamsFieldRelationIds, List<Long> paramsFieldRelationIds) {
        int maxSort = this.interfaceParamsFieldRelationMapper.getMaxSort("2", bffParamReq.getInterfaceId(), bffParamReq.getIsInParam()) + 1;
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationIds)) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
            interfaceParamsFieldRelation.setIds(interfaceParamsFieldRelationIds);
            List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList2 = interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation);
            for (InterfaceParamsFieldRelation paramsFieldRelation : interfaceParamsFieldRelationList2) {
                paramsFieldRelation.setDataRelationId(paramsFieldRelation.getId());
                paramsFieldRelation.setIsRequiredParent(paramsFieldRelation.getIsRequired());
                paramsFieldRelation.setId(null);
                paramsFieldRelation.setType("2");
                paramsFieldRelation.setDataRelationInterfaceId(paramsFieldRelation.getInterfaceId());
                paramsFieldRelation.setInterfaceId(bffParamReq.getInterfaceId());
                paramsFieldRelation.setIsInParam(bffParamReq.getIsInParam());
                paramsFieldRelation.setObjectType("1");
                paramsFieldRelation.setSortNum(maxSort ++);
                paramsFieldRelation.setDataRelationType("1");
                if (StringUtils.isNotEmpty(paramsFieldRelation.getDesignContent())) {
                    paramsFieldRelation.setIsUpdate("N");
                }
                interfaceParamsFieldRelationList.add(paramsFieldRelation);
            }
        }
        if (CollectionUtil.isNotEmpty(paramsFieldRelationIds)) {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setIds(paramsFieldRelationIds);
            List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationMapper.selectParamsFieldRelations(paramsFieldRelation);
            for (ParamsFieldRelation fieldRelation : paramsFieldRelationList) {
                InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
                interfaceParamsFieldRelation.setDataRelationId(fieldRelation.getId());
                interfaceParamsFieldRelation.setIsRequiredParent(fieldRelation.getIsRequired());
                interfaceParamsFieldRelation.setType("2");
                interfaceParamsFieldRelation.setObjectType("1");
                interfaceParamsFieldRelation.setObjectId(fieldRelation.getFieldId());
                interfaceParamsFieldRelation.setDataRelationType("2");
                interfaceParamsFieldRelation.setSortNum(maxSort ++);
                interfaceParamsFieldRelation.setInterfaceId(bffParamReq.getInterfaceId());
                interfaceParamsFieldRelation.setIsInParam(bffParamReq.getIsInParam());
                interfaceParamsFieldRelation.setDataRelationInterfaceId(fieldRelation.getInterfaceId());
                interfaceParamsFieldRelation.setFieldDescription(fieldRelation.getFieldDescription());
                interfaceParamsFieldRelation.setDesignContent(fieldRelation.getDesignContent());
                interfaceParamsFieldRelation.setOrderType(fieldRelation.getOrderType());
                interfaceParamsFieldRelation.setIsRequired(fieldRelation.getIsRequired());
                interfaceParamsFieldRelation.setAliasZhName(fieldRelation.getAliasZhName());
                interfaceParamsFieldRelation.setAliasName(fieldRelation.getAliasName());
                interfaceParamsFieldRelation.setDictCategory(fieldRelation.getDictCategory());
                interfaceParamsFieldRelation.setDictType(fieldRelation.getDictType());
                interfaceParamsFieldRelation.setDictValue(fieldRelation.getDictValue());
                if (StringUtils.isNotEmpty(fieldRelation.getDesignContent())) {
                    interfaceParamsFieldRelation.setIsUpdate("N");
                }

                interfaceParamsFieldRelationList.add(interfaceParamsFieldRelation);
            }

        }
        this.interfaceParamsFieldRelationMapper.batchSave(interfaceParamsFieldRelationList);
        if (bffParamReq.getIsInParam().equals("1")) {
            List<VirtualUsageParamSource> virtualUsageParamSourceList = new ArrayList<>();
            for (InterfaceParamsFieldRelation interfaceParamsFieldRelation : interfaceParamsFieldRelationList) {
                VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                virtualUsageParamSource.setObjectId(interfaceParamsFieldRelation.getDataRelationId());
                virtualUsageParamSource.setType(interfaceParamsFieldRelation.getDataRelationType());
                virtualUsageParamSource.setSourceobjectId(interfaceParamsFieldRelation.getId());
                virtualUsageParamSource.setSourceType("1");
                virtualUsageParamSource.setInterfaceId(interfaceParamsFieldRelation.getDataRelationInterfaceId());
                int i = this.virtualUsageParamSourceMapper.update(virtualUsageParamSource);
                if (i == 0) {
                    this.virtualUsageParamSourceMapper.insertVirtualUsageParamSource(virtualUsageParamSource);
                }
            }
        }
    }

    @Override
    public void saveDubboParam(BffParamReq bffParamReq, List<Long> interfaceParamsFieldRelationIds, List<Long> paramsFieldRelationIds) {
        int maxSort = this.interfaceParamsFieldRelationMapper.getMaxSort("4", bffParamReq.getInterfaceId(), bffParamReq.getIsInParam()) + 1;
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationIds)) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
            interfaceParamsFieldRelation.setIds(interfaceParamsFieldRelationIds);
            List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList2 = interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation);
            for (InterfaceParamsFieldRelation paramsFieldRelation : interfaceParamsFieldRelationList2) {
                paramsFieldRelation.setDataRelationId(paramsFieldRelation.getId());
                paramsFieldRelation.setIsRequiredParent(paramsFieldRelation.getIsRequired());
                paramsFieldRelation.setId(null);
                paramsFieldRelation.setType("4");
                paramsFieldRelation.setDataRelationInterfaceId(paramsFieldRelation.getInterfaceId());
                paramsFieldRelation.setInterfaceId(bffParamReq.getInterfaceId());
                paramsFieldRelation.setIsInParam(bffParamReq.getIsInParam());
                paramsFieldRelation.setObjectType("1");
                paramsFieldRelation.setSortNum(maxSort ++);
                paramsFieldRelation.setDataRelationType("1");
                if (StringUtils.isNotEmpty(paramsFieldRelation.getDesignContent())) {
                    paramsFieldRelation.setIsUpdate("N");
                }
                interfaceParamsFieldRelationList.add(paramsFieldRelation);
            }
        }
        if (CollectionUtil.isNotEmpty(paramsFieldRelationIds)) {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setIds(paramsFieldRelationIds);
            List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationMapper.selectParamsFieldRelations(paramsFieldRelation);
            for (ParamsFieldRelation fieldRelation : paramsFieldRelationList) {
                InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
                interfaceParamsFieldRelation.setDataRelationId(fieldRelation.getId());
                interfaceParamsFieldRelation.setIsRequiredParent(fieldRelation.getIsRequired());
                interfaceParamsFieldRelation.setType("4");
                interfaceParamsFieldRelation.setObjectType("1");
                interfaceParamsFieldRelation.setObjectId(fieldRelation.getFieldId());
                interfaceParamsFieldRelation.setDataRelationType("2");
                interfaceParamsFieldRelation.setSortNum(maxSort ++);
                interfaceParamsFieldRelation.setInterfaceId(bffParamReq.getInterfaceId());
                interfaceParamsFieldRelation.setIsInParam(bffParamReq.getIsInParam());
                interfaceParamsFieldRelation.setFieldDescription(fieldRelation.getFieldDescription());
                interfaceParamsFieldRelation.setDesignContent(fieldRelation.getDesignContent());
                interfaceParamsFieldRelation.setOrderType(fieldRelation.getOrderType());
                interfaceParamsFieldRelation.setIsRequired(fieldRelation.getIsRequired());
                interfaceParamsFieldRelation.setDataRelationInterfaceId(fieldRelation.getInterfaceId());
                interfaceParamsFieldRelation.setAliasZhName(fieldRelation.getAliasZhName());
                interfaceParamsFieldRelation.setAliasName(fieldRelation.getAliasName());
                interfaceParamsFieldRelation.setDictCategory(fieldRelation.getDictCategory());
                interfaceParamsFieldRelation.setDictType(fieldRelation.getDictType());
                interfaceParamsFieldRelation.setDictValue(fieldRelation.getDictValue());
                if (StringUtils.isNotEmpty(fieldRelation.getDesignContent())) {
                    interfaceParamsFieldRelation.setIsUpdate("N");
                }
                interfaceParamsFieldRelationList.add(interfaceParamsFieldRelation);
            }

        }
        this.interfaceParamsFieldRelationMapper.batchSave(interfaceParamsFieldRelationList);
        if (bffParamReq.getIsInParam().equals("1")) {
            List<VirtualUsageParamSource> virtualUsageParamSourceList = new ArrayList<>();
            for (InterfaceParamsFieldRelation interfaceParamsFieldRelation : interfaceParamsFieldRelationList) {
                VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                virtualUsageParamSource.setObjectId(interfaceParamsFieldRelation.getDataRelationId());
                virtualUsageParamSource.setType(interfaceParamsFieldRelation.getDataRelationType());
                virtualUsageParamSource.setSourceobjectId(interfaceParamsFieldRelation.getId());
                virtualUsageParamSource.setSourceType("1");
                virtualUsageParamSource.setInterfaceId(interfaceParamsFieldRelation.getDataRelationInterfaceId());
                int i = this.virtualUsageParamSourceMapper.update(virtualUsageParamSource);
                if (i == 0) {
                    this.virtualUsageParamSourceMapper.insertVirtualUsageParamSource(virtualUsageParamSource);
                }
            }
        }
    }

    @Resource
    private FrontInterfaceFieldSourceMapper frontInterfaceFieldSourceMapper;
    @Resource
    private VirtualUsageFieldMergeMapper virtualUsageFieldMergeMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeField(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        String type = interfaceParamsFieldRelation.getType();
        Long interfaceId = interfaceParamsFieldRelation.getInterfaceId();
        boolean isBranch = false;
        if ("5".equals(type)) {
            isBranch = true;
        } else {
            if ("3".equals(type)) {
                VirtualUsage virtualUsage1 = this.virtualUsageService.selectVirtualUsageById(interfaceId);
                interfaceId = virtualUsage1.getRelationInterfaceId();
            }
            InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
            isBranch = "Y".equals(interfaceInfo.getIsBranch());
        }
        if (interfaceParamsFieldRelation.getObjectType().equals("2")) {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setInterfaceDataListId(interfaceParamsFieldRelation.getId());
            List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationMapper.selectParamsFieldRelationList(paramsFieldRelation);
            if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                List<Long> collect = paramsFieldRelationList.stream().map(o -> o.getId()).collect(Collectors.toList());
                this.virtualUsageParamSourceMapper.deleteByObjectId(collect, "2");
                this.checkFieldSource(collect, "2", isBranch);
                this.checkProcess(collect, "2", isBranch);
                if ("3".equals(type)) {
                    // 删除字段融合数据
                    this.virtualUsageFieldMergeMapper.deleteByMergeObjectIds(collect);
                }
            }
            this.paramsFieldRelationMapper.removeByInterfaceDataListId(Collections.singletonList(interfaceParamsFieldRelation.getId()));
        }

        this.interfaceParamsFieldRelationMapper.deleteInterfaceParamsFieldRelationById(interfaceParamsFieldRelation.getId());

        // 删除来源
        this.virtualUsageParamSourceMapper.deleteByObjectId(Arrays.asList(interfaceParamsFieldRelation.getId()), "1");
        this.checkFieldSource(Arrays.asList(interfaceParamsFieldRelation.getId()), "1", isBranch);
        this.checkProcess(Arrays.asList(interfaceParamsFieldRelation.getId()), "1", isBranch);
        if ("2".equals(type)) {
            // 删除前端字段来源
            this.frontInterfaceFieldSourceMapper.deleteBySourceObjectIdAndSourceObjectFieldId(interfaceParamsFieldRelation.getId(), null);
        }
    }

    @Resource
    private IProcessBranchService processBranchService;
    @Resource
    private IProcessBranchConditionService processBranchConditionService;
    @Resource
    private IProcessBranchConditionDetailService processBranchConditionDetailService;
    @Resource
    private IVirtualUsageService virtualUsageService;
    @Resource
    private IInterfaceInfoService interfaceInfoService;
    @Resource
    private IVirtualUsageGroupService virtualUsageGroupService;

    private void checkProcess(List<Long> ids, String type,boolean isBranch) {
        if (!isBranch) return;
        ProcessBranchConditionDetail processBranchConditionDetail = new ProcessBranchConditionDetail();
        if ("1".equals(type)) {
            processBranchConditionDetail.setObjectType("1");
            processBranchConditionDetail.setObjectIds(ids);
        } else {
            processBranchConditionDetail.setParamsIds(ids);
            processBranchConditionDetail.setObjectType("3");
        }
        List<ProcessBranchConditionDetail> processBranchConditionDetails = this.processBranchConditionDetailService.selectProcessBranchConditionDetailList(processBranchConditionDetail);
        if (CollectionUtil.isNotEmpty(processBranchConditionDetails)) {
            for (ProcessBranchConditionDetail branchConditionDetail : processBranchConditionDetails) {
                ProcessBranchCondition processBranchCondition = this.processBranchConditionService.selectProcessBranchConditionByBranchConditionId(branchConditionDetail.getBranchConditionId());
                if (processBranchCondition != null) {
                    InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(branchConditionDetail.getBranchInterfaceId());
                    if (interfaceInfo != null) {
                        String result = "被" + interfaceInfo.getInterfaceName() + " 分支流程引用（" + processBranchCondition.getBranchConditionName() + ")";
                        throw new BusinessException(result);
                    }
                }
            }
        }
    }

    private void checkFieldSource(List<Long> ids, String type, boolean isBranch) {
        VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
        virtualUsageParamSource.setSourceObjectIds(ids);
        virtualUsageParamSource.setSourceType(type);
        List<VirtualUsageParamSource> virtualUsageParamSourceList = this.virtualUsageParamSourceMapper.selectVirtualUsageParamSourceList(virtualUsageParamSource);
        if (CollectionUtil.isNotEmpty(virtualUsageParamSourceList)) {
            for (VirtualUsageParamSource paramSource : virtualUsageParamSourceList) {
                String result = "";
                if (paramSource.getIsInParam().equals("2")) {
                    InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(paramSource.getInterfaceId());
                    if (interfaceInfo != null) {
                        result = "被" + interfaceInfo.getInterfaceName() + "出参引用";
                    }
                } else {
                    if (paramSource.getVirtualUsageGroupId() == null) {
                        if ((isBranch && paramSource.getProcessBranchId() != null) || (!isBranch && paramSource.getProcessBranchId() == null)) {
                            // 判断字段是否存在
                            if ("1".equals(paramSource.getType())) {
                                InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationById(paramSource.getObjectId());
                                if (interfaceParamsFieldRelation == null) continue;
                            } else {
                                ParamsFieldRelation paramsFieldRelation = this.paramsFieldRelationMapper.selectParamsFieldRelationById(paramSource.getObjectId());
                                if (paramsFieldRelation == null) continue;
                            }
                            VirtualUsage virtualUsage1 = new VirtualUsage();
                            virtualUsage1.setId(paramSource.getInterfaceId());
                            List<VirtualUsage> virtualUsages1 = this.virtualUsageService.selectVirtualUsages(virtualUsage1);
                            if (CollectionUtil.isNotEmpty(virtualUsages1)) {
                                result = "被" + virtualUsages1.get(0).getMasterInterfaceName() + " 下 " + virtualUsages1.get(0).getSlaveInterfaceName() + " 入参引用";
                            }
                        }
                    } else {
                        VirtualUsageGroup virtualUsageGroup = this.virtualUsageGroupService.selectVirtualUsageGroupById(paramSource.getVirtualUsageGroupId());
                        if (virtualUsageGroup != null) {
                            InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(virtualUsageGroup.getInterfaceId());
                            if (interfaceInfo != null) {
                                result = "被" + interfaceInfo.getInterfaceName() + "下 " + virtualUsageGroup.getGroupName() + " ";
                                VirtualUsage virtualUsage1 = new VirtualUsage();
                                virtualUsage1.setId(paramSource.getInterfaceId());
                                List<VirtualUsage> virtualUsages1 = this.virtualUsageService.selectVirtualUsages(virtualUsage1);
                                if (CollectionUtil.isNotEmpty(virtualUsages1)) {
                                    result += virtualUsages1.get(0).getSlaveInterfaceName() + " 入参引用";
                                }
                            }
                        }
                    }
                }
                if (StringUtils.isNotEmpty(result)) {
                    throw new BusinessException(result);
                }
            }
        }
    }

    @Override
    public List<InterfaceParamsFieldRelation> selectInterfaceParamsFieldRelationByDataRelationId(List<Long> ids, String dataRelationType) {
        return this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationByDataRelationId(ids, dataRelationType);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateFieldDesign(InterfaceParamsFieldRelation fieldRelation) {
        Long id = fieldRelation.getId();
        String type = fieldRelation.getType();
        String fieldDescription = fieldRelation.getFieldDescription();
        String designContent = fieldRelation.getDesignContent();
        String orderType = fieldRelation.getOrderType();
        String isRequired = fieldRelation.getIsRequired();
        String isUpdate = fieldRelation.getIsUpdate();
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
        interfaceParamsFieldRelation.setId(id);
        interfaceParamsFieldRelation.setFieldDescription(fieldDescription);
        interfaceParamsFieldRelation.setDesignContent(designContent);
        interfaceParamsFieldRelation.setOrderType(orderType);
        interfaceParamsFieldRelation.setIsRequired(isRequired);
        interfaceParamsFieldRelation.setDictCategory(fieldRelation.getDictCategory());
        interfaceParamsFieldRelation.setDictType(fieldRelation.getDictType());
        interfaceParamsFieldRelation.setDictValue(fieldRelation.getDictValue());
        ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
        paramsFieldRelation.setFieldDescription(fieldDescription);
        paramsFieldRelation.setDesignContent(designContent);
        paramsFieldRelation.setOrderType(orderType);
        paramsFieldRelation.setIsRequired(isRequired);
        paramsFieldRelation.setDictCategory(fieldRelation.getDictCategory());
        paramsFieldRelation.setDictType(fieldRelation.getDictType());
        paramsFieldRelation.setDictValue(fieldRelation.getDictValue());
        paramsFieldRelation.setId(id);
        if (type.equals("1")) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation1 = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationById(id);
            interfaceParamsFieldRelation.setIsUpdate(interfaceParamsFieldRelation1.getIsUpdate());
            interfaceParamsFieldRelation.setStatusId(interfaceParamsFieldRelation1.getStatusId());
            this.interfaceParamsFieldRelationMapper.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
            interfaceParamsFieldRelation.setIsRequiredParent(isRequired);
            //"BFF 和 DUBBO 接口设置必填后，虚拟用况继承，不用在选一次了
            if (interfaceParamsFieldRelation1.getType().equals("2")
                || interfaceParamsFieldRelation1.getType().equals("4")) {
                if (interfaceParamsFieldRelation1.getDataRelationId() != null) {
                    if ("1".equals(interfaceParamsFieldRelation1.getDataRelationType())) {
                        InterfaceParamsFieldRelation interfaceParamsFieldRelation2 = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationById(interfaceParamsFieldRelation1.getDataRelationId());
                        interfaceParamsFieldRelation2.setFieldDescription(fieldDescription);
                        interfaceParamsFieldRelation2.setDesignContent(designContent);
                        interfaceParamsFieldRelation2.setOrderType(orderType);
                        interfaceParamsFieldRelation2.setIsRequired(isRequired);
                        interfaceParamsFieldRelation2.setDictCategory(fieldRelation.getDictCategory());
                        interfaceParamsFieldRelation2.setDictType(fieldRelation.getDictType());
                        interfaceParamsFieldRelation2.setDictValue(fieldRelation.getDictValue());
                        this.interfaceParamsFieldRelationMapper.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation2);
                    } else {
                        ParamsFieldRelation paramsFieldRelation1 = this.paramsFieldRelationMapper.selectParamsFieldRelationById(interfaceParamsFieldRelation1.getDataRelationId());
                        paramsFieldRelation1.setFieldDescription(fieldDescription);
                        paramsFieldRelation1.setDesignContent(designContent);
                        paramsFieldRelation1.setOrderType(orderType);
                        paramsFieldRelation1.setIsRequired(isRequired);
                        paramsFieldRelation1.setDictCategory(fieldRelation.getDictCategory());
                        paramsFieldRelation1.setDictType(fieldRelation.getDictType());
                        paramsFieldRelation1.setDictValue(fieldRelation.getDictValue());
                        this.paramsFieldRelationMapper.updateParamsFieldRelation(paramsFieldRelation1);
                    }
                }
            }
        } else {
            ParamsFieldRelation paramsFieldRelation1 = this.paramsFieldRelationMapper.selectParamsFieldRelationById(id);
            paramsFieldRelation.setIsUpdate(paramsFieldRelation1.getIsUpdate());
            this.paramsFieldRelationMapper.updateParamsFieldRelation(paramsFieldRelation);
            paramsFieldRelation.setIsRequiredParent(isRequired);
            InterfaceParamsFieldRelation interfaceParamsFieldRelation1 = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationById(paramsFieldRelation1.getInterfaceDataListId());
            //"BFF 和 DUBBO 接口设置必填后，虚拟用况继承，不用在选一次了
            if (interfaceParamsFieldRelation1.getType().equals("2")
                    || interfaceParamsFieldRelation1.getType().equals("4")) {
                if (paramsFieldRelation1.getDataRelationId() != null) {
                    if ("1".equals(paramsFieldRelation1.getDataRelationType())) {
                        InterfaceParamsFieldRelation interfaceParamsFieldRelation2 = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationById(paramsFieldRelation1.getDataRelationId());
                        interfaceParamsFieldRelation2.setFieldDescription(fieldDescription);
                        interfaceParamsFieldRelation2.setDesignContent(designContent);
                        interfaceParamsFieldRelation2.setOrderType(orderType);
                        interfaceParamsFieldRelation2.setIsRequired(isRequired);
                        interfaceParamsFieldRelation2.setDictCategory(fieldRelation.getDictCategory());
                        interfaceParamsFieldRelation2.setDictType(fieldRelation.getDictType());
                        interfaceParamsFieldRelation2.setDictValue(fieldRelation.getDictValue());
                        this.interfaceParamsFieldRelationMapper.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation2);
                    } else {
                        ParamsFieldRelation paramsFieldRelation2 = this.paramsFieldRelationMapper.selectParamsFieldRelationById(paramsFieldRelation1.getDataRelationId());
                        paramsFieldRelation2.setFieldDescription(fieldDescription);
                        paramsFieldRelation2.setDesignContent(designContent);
                        paramsFieldRelation2.setOrderType(orderType);
                        paramsFieldRelation2.setIsRequired(isRequired);
                        paramsFieldRelation2.setDictCategory(fieldRelation.getDictCategory());
                        paramsFieldRelation2.setDictType(fieldRelation.getDictType());
                        paramsFieldRelation2.setDictValue(fieldRelation.getDictValue());
                        this.paramsFieldRelationMapper.updateParamsFieldRelation(paramsFieldRelation2);
                    }
                }
            }
        }
        interfaceParamsFieldRelation.setIsUpdate(isUpdate);
        paramsFieldRelation.setIsUpdate(isUpdate);

        List<Long> ids = Arrays.asList(id);
        // 更新子集
        if (type.equals("1")) {
            this.updateInterfaceParamsFieldRelationFieldDesign(interfaceParamsFieldRelation, paramsFieldRelation, ids);
        } else {
            this.updateParamsFieldRelationFieldDesign(interfaceParamsFieldRelation, paramsFieldRelation, ids);
        }
    }

    @Override
    public void saveGroupParam(BffParamReq bffParamReq, List<Long> interfaceParamsFieldRelationIds, List<Long> paramsFieldRelationIds) {
        int maxSort = this.interfaceParamsFieldRelationMapper.getMaxSort("5", bffParamReq.getInterfaceId(), bffParamReq.getIsInParam()) + 1;
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationIds)) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
            interfaceParamsFieldRelation.setIds(interfaceParamsFieldRelationIds);
            List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList2 = interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation);
            for (InterfaceParamsFieldRelation paramsFieldRelation : interfaceParamsFieldRelationList2) {
                paramsFieldRelation.setDataRelationId(paramsFieldRelation.getId());
                paramsFieldRelation.setIsRequiredParent(paramsFieldRelation.getIsRequired());
                paramsFieldRelation.setId(null);
                paramsFieldRelation.setType("5");
                paramsFieldRelation.setDataRelationInterfaceId(paramsFieldRelation.getInterfaceId());
                paramsFieldRelation.setInterfaceId(bffParamReq.getInterfaceId());
                paramsFieldRelation.setIsInParam(bffParamReq.getIsInParam());
                paramsFieldRelation.setObjectType("1");
                paramsFieldRelation.setSortNum(maxSort ++);
                paramsFieldRelation.setDataRelationType("1");
                if (StringUtils.isNotEmpty(paramsFieldRelation.getDesignContent())) {
                    paramsFieldRelation.setIsUpdate("N");
                }
                interfaceParamsFieldRelationList.add(paramsFieldRelation);
            }
        }
        if (CollectionUtil.isNotEmpty(paramsFieldRelationIds)) {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setIds(paramsFieldRelationIds);
            List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationMapper.selectParamsFieldRelations(paramsFieldRelation);
            for (ParamsFieldRelation fieldRelation : paramsFieldRelationList) {
                InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
                interfaceParamsFieldRelation.setDataRelationId(fieldRelation.getId());
                interfaceParamsFieldRelation.setIsRequiredParent(fieldRelation.getIsRequired());
                interfaceParamsFieldRelation.setType("5");
                interfaceParamsFieldRelation.setObjectType("1");
                interfaceParamsFieldRelation.setObjectId(fieldRelation.getFieldId());
                interfaceParamsFieldRelation.setDataRelationType("2");
                interfaceParamsFieldRelation.setSortNum(maxSort ++);
                interfaceParamsFieldRelation.setInterfaceId(bffParamReq.getInterfaceId());
                interfaceParamsFieldRelation.setIsInParam(bffParamReq.getIsInParam());
                interfaceParamsFieldRelation.setDataRelationInterfaceId(fieldRelation.getInterfaceId());
                interfaceParamsFieldRelation.setFieldDescription(fieldRelation.getFieldDescription());
                interfaceParamsFieldRelation.setDesignContent(fieldRelation.getDesignContent());
                interfaceParamsFieldRelation.setOrderType(fieldRelation.getOrderType());
                interfaceParamsFieldRelation.setIsRequired(fieldRelation.getIsRequired());
                interfaceParamsFieldRelation.setAliasZhName(fieldRelation.getAliasZhName());
                interfaceParamsFieldRelation.setAliasName(fieldRelation.getAliasName());
                interfaceParamsFieldRelation.setDictCategory(fieldRelation.getDictCategory());
                interfaceParamsFieldRelation.setDictType(fieldRelation.getDictType());
                interfaceParamsFieldRelation.setDictValue(fieldRelation.getDictValue());
                if (StringUtils.isNotEmpty(fieldRelation.getDesignContent())) {
                    interfaceParamsFieldRelation.setIsUpdate("N");
                }

                interfaceParamsFieldRelationList.add(interfaceParamsFieldRelation);
            }

        }
        this.interfaceParamsFieldRelationMapper.batchSave(interfaceParamsFieldRelationList);
        if (bffParamReq.getIsInParam().equals("1")) {
            List<VirtualUsageParamSource> virtualUsageParamSourceList = new ArrayList<>();
            for (InterfaceParamsFieldRelation interfaceParamsFieldRelation : interfaceParamsFieldRelationList) {
                VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                virtualUsageParamSource.setObjectId(interfaceParamsFieldRelation.getDataRelationId());
                virtualUsageParamSource.setType(interfaceParamsFieldRelation.getDataRelationType());
                virtualUsageParamSource.setSourceobjectId(interfaceParamsFieldRelation.getId());
                virtualUsageParamSource.setSourceType("1");
                virtualUsageParamSource.setInterfaceId(interfaceParamsFieldRelation.getDataRelationInterfaceId());
                virtualUsageParamSource.setVirtualUsageGroupId(bffParamReq.getInterfaceId());
                int i = this.virtualUsageParamSourceMapper.update(virtualUsageParamSource);
                if (i == 0) {
                    this.virtualUsageParamSourceMapper.insertVirtualUsageParamSource(virtualUsageParamSource);
                }
            }
        }
    }

    private void updateInterfaceParamsFieldRelationFieldDesign(InterfaceParamsFieldRelation interfaceParamsFieldRelation, ParamsFieldRelation paramsFieldRelation, List<Long> ids) {
        if (!CollectionUtil.isNotEmpty(ids)) return;
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationByDataRelationId(ids, "1");
        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
            ids = interfaceParamsFieldRelationList.stream().map(InterfaceParamsFieldRelation::getId).collect(Collectors.toList());
            this.interfaceParamsFieldRelationMapper.updateFieldDesign(interfaceParamsFieldRelation, ids);
            this.updateInterfaceParamsFieldRelationFieldDesign(interfaceParamsFieldRelation, paramsFieldRelation, ids);
        }
        List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationMapper.selectParamsFieldRelationByDataRelationId(ids, "1");
        if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
            ids = paramsFieldRelationList.stream().map(ParamsFieldRelation::getId).collect(Collectors.toList());
            this.paramsFieldRelationMapper.updateFieldDesign(paramsFieldRelation, ids);
            this.updateParamsFieldRelationFieldDesign(interfaceParamsFieldRelation, paramsFieldRelation, ids);
        }
    }

    private void updateParamsFieldRelationFieldDesign(InterfaceParamsFieldRelation interfaceParamsFieldRelation, ParamsFieldRelation paramsFieldRelation, List<Long> ids) {
        if (!CollectionUtil.isNotEmpty(ids)) return;
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationMapper.selectInterfaceParamsFieldRelationByDataRelationId(ids, "2");
        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
            ids = interfaceParamsFieldRelationList.stream().map(InterfaceParamsFieldRelation::getId).collect(Collectors.toList());
            this.interfaceParamsFieldRelationMapper.updateFieldDesign(interfaceParamsFieldRelation, ids);
            this.updateInterfaceParamsFieldRelationFieldDesign(interfaceParamsFieldRelation, paramsFieldRelation, ids);
        }
        List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationMapper.selectParamsFieldRelationByDataRelationId(ids, "2");
        if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
            ids = paramsFieldRelationList.stream().map(ParamsFieldRelation::getId).collect(Collectors.toList());
            this.paramsFieldRelationMapper.updateFieldDesign(paramsFieldRelation, ids);
            this.updateParamsFieldRelationFieldDesign(interfaceParamsFieldRelation, paramsFieldRelation, ids);
        }
    }
}
